using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDF.Data;
using DDF.Data.Providers;
using System.Data;
using System.Linq.Expressions;
using System.Configuration;
using ARR.Entities.Gateways;

namespace ARR.DataModel.Repositories
{
	public static partial class TempArticleSalesStoresAverageRepository
	{
		private static string connString = ConfigurationManager.ConnectionStrings["Default"].ConnectionString;
		
		public class TempArticleSalesStoresAverageDbo : DatabaseObject
        {
            public TempArticleSalesStoresAverageDbo()
            {
                Name = "TempArticleSalesStoresAverage";
                GeneratedClassName = "TempArticleSalesStoresAverage";
                SequenceName = "N/A";
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "StoreName", ColumnType = "varchar", IsIdentity = false, IsNullable = true, Length = 200, Precision = 0, Scale = 0, GeneratedPropertyName = "StoreName" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Date", ColumnType = "date", IsIdentity = false, IsNullable = false, Length = 3, Precision = 10, Scale = 0, GeneratedPropertyName = "Date" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Sales", ColumnType = "money", IsIdentity = false, IsNullable = true, Length = 8, Precision = 19, Scale = 4, GeneratedPropertyName = "Sales" });
					Columns.Add(new DatabaseObjectColumn() { ColumnName = "Margin", ColumnType = "money", IsIdentity = false, IsNullable = true, Length = 8, Precision = 19, Scale = 4, GeneratedPropertyName = "Margin" });
              
            }
        }
		
		public static List<TempArticleSalesStoresAverageRow> Select(Expression<Func<TempArticleSalesStoresAverageRow, bool>> expression)
        {
            List<TempArticleSalesStoresAverageRow> rows = new List<TempArticleSalesStoresAverageRow>();

            using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
            {
                IDataReader reader = database.Select<TempArticleSalesStoresAverageRow>(new TempArticleSalesStoresAverageDbo(), expression);

                Load(reader, rows);
            }

            return rows;
        }
		
		public static List<TempArticleSalesStoresAverageRow> Select()
		{
			List<TempArticleSalesStoresAverageRow> rows = new List<TempArticleSalesStoresAverageRow>();

			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.Select<TempArticleSalesStoresAverageRow>(new TempArticleSalesStoresAverageDbo(), null);

				Load(reader, rows);
			}

			return rows;
		}
		
		public static List<TempArticleSalesStoresAverageRow> PagedSelect(Expression<Func<TempArticleSalesStoresAverageRow, bool>> filterExpression, Expression<Func<TempArticleSalesStoresAverageRow, object>> orderByExpression, int pageNumber, int pageSize)
		{
			List<TempArticleSalesStoresAverageRow> rows = new List<TempArticleSalesStoresAverageRow>();
			
			using (Database database = new SqlDataProvider(connString, "{0}Cursor", "dbo"))
			{
				IDataReader reader = database.PagedSelect<TempArticleSalesStoresAverageRow>(new TempArticleSalesStoresAverageDbo(), filterExpression, orderByExpression, pageNumber, pageSize);

				Load(reader, rows);
			}

			return rows;
		}
		
		private static void Load(IDataReader reader, List<TempArticleSalesStoresAverageRow> TempArticleSalesStoresAverageList)
        {
            TempArticleSalesStoresAverageRow row;

            while (reader.Read())
            {
                row = new TempArticleSalesStoresAverageRow()
                {
					StoreName = Util.CastDbValue<string>(reader["StoreName"]),
					Date = Util.CastDbValue<DateTime>(reader["Date"]),
					Sales = Util.CastDbValue<decimal?>(reader["Sales"]),
					Margin = Util.CastDbValue<decimal?>(reader["Margin"])
                };
                                
                TempArticleSalesStoresAverageList.Add(row);
            }

            reader.Close();
        }

		
		
		
	}
}
	
